<?php

namespace Biz\model\brandDecoration;

use Doraemon\pockets\datebase\BaseDbModel;

class BrandCardListing extends BaseDbModel
{

    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'hhz_store';

    const _TABLE_NAME = 'brand_card_listing';

    const NORMAL_STATUS = 1;
    const DELETE_STATUS = 9;
    const OVER_STATUS = 10;//审核不通过

    const LINK_TYPE_NOTE = 1;
    const LINK_TYPE_ARTICLE = 2;
    const LINK_TYPE_BLANK = 3;
    const LINK_TYPE_WIKI = 4;
    const LINK_TYPE_H5 = 5;
    const LINK_TYPE_H5_INNER = 6;
    const LINK_TYPE_VIDEO = 7;
    const NEED_CHECK = [
        self::LINK_TYPE_H5
    ];
    const MODULE_NOTHING = 0;
    const MODULE_TAOBAO = 1;
    const MODULE_JINGDONG = 2;
    const LINK_MODULE = [
        self::MODULE_NOTHING => '-',
        self::MODULE_TAOBAO => '淘宝',
        self::MODULE_JINGDONG => '京东'
    ];

    const CHECK_STATUS_READY = 0;
    const CHECK_STATUS_PASS = 1;
    const CHECK_STATUS_OVER = 2;
    const CHECK_STATUS = [
        self::CHECK_STATUS_READY => '待审核',
        self::CHECK_STATUS_PASS => '审核通过',
        self::CHECK_STATUS_OVER => '审核不通过',
    ];


    public static function getCardInfos($brand_id)
    {
        return self::select('*', [
            'brand_id' => $brand_id,
            'li_status' => [self::NORMAL_STATUS, self::OVER_STATUS],
            'ORDER' => [
                'inner_sort' => 'ASC'
            ]
        ]);
    }

    public static function getCardInfosForApp($brand_id)
    {
        return self::select('*', [
            'brand_id' => $brand_id,
            'li_status' => [self::NORMAL_STATUS],
            'ORDER' => [
                'inner_sort' => 'ASC'
            ]
        ]);
    }

    public static function getHeadPicByCardId($card_id)
    {
        return self::get('*', [
            'card_id' => $card_id,
            'li_status' => self::NORMAL_STATUS
        ]);
    }

    //添加
    public static function addData($data)
    {
        return self::insert($data);
    }

    //修改
    public static function editData($data, $where = [])
    {
        return self::update($data, $where);
    }

    //后台筛选使用
    public static function getInfosByWhere($where, $start = 0, $limit = 20)
    {
        $where = array_merge($where, ['LIMIT' => [$start, $limit], 'ORDER' => ['addtime' => 'ASC'], 'link_type' => self::NEED_CHECK]);
        return self::select("*", $where);
    }

    public static function getInfosCount($where)
    {
        $where = array_merge($where, ['link_type' => self::NEED_CHECK]);
        return self::count("*", $where);
    }

}

